package com.kerrykidz.system.util.security;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class PermissionObj implements Serializable, Comparable<PermissionObj> {

	private static final long serialVersionUID = 1L;

	public PermissionObj() {

	}

	public PermissionObj(String type, String desc, String name, String padName, String id, String pid, Integer ordInd) {
		this.type = type;
		this.desc = desc;
		this.name = name;
		this.padName = padName;
		this.id = id;
		this.pid = pid;
		this.ordInd = ordInd;
	}

	private String type;
	private String desc;
	private String name;
	private String padName;
	private String id;
	private String pid;
	private Integer ordInd;
	private String cssName;
	private List<PermissionObj> children;

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPadName() {
		return padName;
	}

	public void setPadName(String padName) {
		this.padName = padName;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getPid() {
		return pid;
	}

	public void setPid(String pid) {
		this.pid = pid;
	}

	public List<PermissionObj> getChildren() {
		return children;
	}

	public void setChildren(List<PermissionObj> children) {
		this.children = children;
	}

	public Integer getOrdInd() {
		return ordInd;
	}

	public void setOrdInd(Integer ordInd) {
		this.ordInd = ordInd;
	}

	public String getCssName() {
		return cssName;
	}

	public void setCssName(String cssName) {
		this.cssName = cssName;
	}

	@Override
	public int compareTo(PermissionObj o) {
		Integer ord2 = o.getOrdInd();
		Integer ord1 = this.getOrdInd();
		ord2 = ord2 == null ? 0 : ord2;
		ord1 = ord1 == null ? 0 : ord1;
		return ord1 - ord2;
	}

	@Override
	public int hashCode() {
		return this.id.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		return obj instanceof PermissionObj && this.id.equals(((PermissionObj) obj).getId());
	}

	public static void main(String[] args) {
		List<PermissionObj> objs = new ArrayList<PermissionObj>();
		objs.add(new PermissionObj(null, null, null, null, "2", "1", 3));
		objs.add(new PermissionObj(null, null, null, null, "2", "1", 33));
		objs.add(new PermissionObj(null, null, null, null, "2", "1", 2));
		objs.add(new PermissionObj(null, null, null, null, "2", "1", 5));
		objs.add(new PermissionObj(null, null, null, null, "2", "1", 22));
		Collections.sort(objs);
		for (PermissionObj o : objs)
			System.out.println(o.getOrdInd());
	}

}
